<template>
	<div class="game-container report-container">
		<div class="view-container dealer-container">
			<div class="params" style="margin-top: -20px;">
				<div class="top-fixed">
					<el-tabs v-model="activeGameType">
						<el-tab-pane
							v-for="item in gameTypesList"
							:label="item.gameTypeName"
							:name="item.gameType"
							:key="item.gameType"
							:disabled="isEdit"
						></el-tab-pane>
					</el-tabs>
				</div>

				<div style="margin-top: 50px;">
					{{ $t('dxn.game_rule.game_rules') }} -
					{{ gameTypeInfo.gameTypeName }}
					<el-divider></el-divider>
					<GameRule
						:gameTypeId="gameTypeInfo.gameTypeId"
						:maxLimit="maxLimit[gameTypeInfo.maxLimit]"
						:bbSettingLabel="gameTypeInfo.bbSettingLabel"
						:unitLabel="gameTypeInfo.unitLabel"
						:unitName="gameTypeInfo.unitName"
						:key="gameRuleKey"
						@getEditLoading="getEditLoading"
					/>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import GameRule from './components/gameRule'
import { routerNames } from '@/utils/consts'
export default {
	name: routerNames.gameRuleManager,
	components: {
		GameRule
	},
	data() {
		return {
			maxTexasK: {
				gameOvertime: 'texas.time.out', // texas.time.out 德州超时(min)自动解散房间
				setting: 'texas.blind.bb', // texas.blind.bb 德州大盲BB
				defaultCarry: 'texas.default.bb', // texas.default.bb 德州默认带入值（倍BB）
				complementLimit: 'texas.lower.limit', // texas.lower.limit 德州补码上下限（倍BB）
				gameTimes: 'texas.duration', // texas.duration 德州时长
				rake: 'bottom.pool.ratio', // bottom.pool.ratio 德州每手牌有效底池抽水比例(%)
				insuranceTurn: 'texas.turn.buy.low.limit', // 购买turn保险最低值
				bottomPoolFee: 'texas.pot.rate.limit', // 德州底池比例收费
				profitFee: 'texas.profit.rate.limit', // 德州盈利比例收费
				tableFeeScale: 'texas.tableFee.rate.limit' // 德州扑克局服务费比例
			},
			maxShortK: {
				gameOvertime: 'short.card.timeout', // short.card.timeout 短牌超时(min)自动解散房间
				setting: 'short.card.ante', // short.card.ante 短牌Ante
				defaultCarry: 'short.card.default', // short.card.default 短牌默认带入值（倍Ante）
				complementLimit: 'short.card.lower.limit', // short.card.lower.limit 短牌补码上下限 倍Ante）
				gameTimes: 'short.card.duration', // short.card.duration 短牌时长
				rake: 'short.card.pool.ratio', // short.card.pool.ratio 短牌每手牌有效底池抽水比例(%)
				insuranceTurn: 'short.turn.buy.low.limit', // 购买turn保险最低值
				bottomPoolFee: 'short.pot.rate.limit', // 短牌底池比例收费
				profitFee: 'short.profit.rate.limit', // 短牌盈利比例收费
				tableFeeScale: 'short.tableFee.rate.limit' // 短牌局服务费比例
			},
			maxLimit: {
				texas: {},
				short: {}
			},
			activeGameType: 'texas',
			gameTypesList: [
				{
					gameType: 'texas',
					gameTypeName: '德州扑克',
					gameTypeId: 1,
					maxLimit: 'texas',
					bbSettingLabel: this.$t('dxn.game_rule.bb'),
					unitLabel: this.$t('dxn.game_rule.bb_unit'),
					unitName: this.$t('dxn.game_rule.insure_trigger_bb')
				},
				{
					gameType: 'short',
					gameTypeName: '短牌',
					gameTypeId: 2,
					maxLimit: 'short',
					bbSettingLabel: this.$t('dxn.game_rule.ante'),
					unitLabel: this.$t('dxn.game_rule.ante_unit'),
					unitName: this.$t('dxn.game_rule.insure_trigger_ante')
				},
				{
					gameType: 'AOFTexas',
					gameTypeName: 'AOF德州',
					gameTypeId: 3,
					maxLimit: 'texas',
					bbSettingLabel: this.$t('dxn.game_rule.bb'),
					unitLabel: this.$t('dxn.game_rule.bb_unit'),
					unitName: this.$t('dxn.game_rule.insure_trigger_bb')
				},
				{
					gameType: 'AOFShort',
					gameTypeName: 'AOF短牌',
					gameTypeId: 4,
					maxLimit: 'short',
					bbSettingLabel: this.$t('dxn.game_rule.ante'),
					unitLabel: this.$t('dxn.game_rule.ante_unit'),
					unitName: this.$t('dxn.game_rule.insure_trigger_ante')
				}
			],
			gameTypeInfo: {},
			gameRuleKey: 0,
			isEdit: false
		}
	},
	watch: {
		activeGameType: {
			handler() {
				this.gameTypeInfo = this.gameTypesList.find(
					(item) => item.gameType === this.activeGameType
				)
				this.gameRuleKey = Math.random()
			},
			immediate: true
		}
	},
	created() {
		this.getGameSystemKvconfigValue()
	},
	methods: {
		getEditLoading(val) {
			this.isEdit = val
		},
		// 获取系统参数字典配置值
		getGameSystemKvconfigValue() {
			Object.keys(this.maxShortK).forEach((key) => {
				this.maxLimit.texas[key] = 0
				this.maxLimit.short[key] = 0
			})
			const params = { tag: 'game' }
			this.$api
				.getSystemKvconfigByTag(params)
				.then((res) => {
					if (res?.code === 200) {
						const configArr = res?.data || []
						configArr.forEach((item) => {
							Object.keys(this.maxTexasK).forEach((key) => {
								if (this.maxTexasK[key] === item.k) {
									this.maxLimit.texas[key] = Number(item.v)
								}
							})
							Object.keys(this.maxShortK).forEach((key) => {
								if (this.maxShortK[key] === item.k) {
									this.maxLimit.short[key] = Number(item.v)
								}
							})
						})
					}
				})
				.catch(() => {})
		}
	}
}
</script>
<style lang="scss" scoped>
::v-deep .el-radio-button__orig-radio:checked + .el-radio-button__inner {
	background-color: #aaaaaa;
	border-color: #aaaaaa;
	-webkit-box-shadow: unset;
	box-shadow: unset;
}
::v-deep .el-radio-button .el-radio-button__inner {
	border-radius: unset;
}
.top-fixed {
	position: fixed;
	top: 110px;
	background-color: white;
	z-index: 8;
	width: 85%;
}
</style>
